package com.yanggeng.demo.beginnerguidedemo.activity.customview;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.EditText;

import com.yanggeng.demo.beginnerguidedemo.R;
import com.yanggeng.demo.beginnerguidedemo.activity.BaseActivity;
import com.yanggeng.demo.beginnerguidedemo.widget.RadarView;

import java.util.LinkedHashMap;
import java.util.Random;

public class RadarViewActivity extends BaseActivity {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_radarview);

        setTitle(true, "雷达图");

        final RadarView radarView = (RadarView) findViewById(R.id.radar_view);
        LinkedHashMap<String, Float> data = new LinkedHashMap<>();
        data.put("物理", 78f);
        data.put("化学", 57f);
        data.put("生物", 98f);
        data.put("语文", 69f);
        data.put("数学", 89f);
        data.put("英语", 68f);
        radarView.setCount(6);
        radarView.setData(data);

        final Animation animation = AnimationUtils.loadAnimation(this, R.anim.anim_scale_loop);
        radarView.setAnimation(animation);

        final EditText editText = (EditText) findViewById(R.id.et_count);
        findViewById(R.id.btn_change_count).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String count = editText.getText().toString().trim();
                if (!TextUtils.isEmpty(count)) {
                    radarView.setCount(Integer.valueOf(count));
                    radarView.setData(getData(Integer.valueOf(count)));
                }
            }
        });

        findViewById(R.id.btn_show_error).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showErrorLayout();
            }
        });

        findViewById(R.id.btn_show_content).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showContent();
            }
        });
    }

    private LinkedHashMap<String, Float> getData(int count) {
        LinkedHashMap<String, Float> data = new LinkedHashMap<>();
        Random random = new Random();
        for (int i = 0; i < count; i++) {
            data.put("text" + i, Float.valueOf(String.valueOf(random.nextInt(100))));
        }
        return data;
    }
}
